package com.csun.dsms;

import com.csun.dsms.comment.config.properties.CsunProperties;
import com.csun.dsms.utils.ApplicationContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import tk.mybatis.spring.annotation.MapperScan;

import javax.annotation.Resource;
import java.util.Locale;


@Slf4j
@SpringBootApplication
@MapperScan("com.csun.dsms.mapper")
public class SpringbootDsmsApplication implements CommandLineRunner {

	@Value("${application.version}")
	private String version;

	@Value("${application.env}")
	private String env;

	public static void main(String[] args) {

		SpringApplication.run(SpringbootDsmsApplication.class, args);

		log.info("spring boot dsms application running...");
	}

	@Bean
	public ReloadableResourceBundleMessageSource messageSource() {
		Locale.setDefault(Locale.CHINA);    // classpath:org/springframework/security/messages_zh_CN
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
		messageSource.setBasenames("classpath:ValidationMessages");
		return messageSource;
	}

	@Bean
	public ApplicationContextUtil applicationContextUtil() {

		return new ApplicationContextUtil();
	}

	@Override
	public void run(String... args) throws Exception {

		log.info("spring boot dsms application env = [{}], version = [{}]", env, version);
	}
}
